<?php 

abstract class sgeGeneratorHelper extends sfModelGeneratorHelper
{

	public function imgLinkToDelete($object, $params)
	{
		if ($object->isNew())
		{
			return '';
		}

		return link_to('<span title="Borrar"></span>', $this->getUrlForAction('delete'), $object, array('method' => 'delete', 'confirm' => '¿Desea eliminar el elemento seleccionado?', 'class' => 'admin_td_action admin_td_action_delete'));
	}

	public function imgLinkToEdit($object, $params)
	{
		return link_to('<span title="Editar"></span>', $this->getUrlForAction('edit'), $object, array('class' => 'admin_td_action admin_td_action_edit'));
	}

	public function imgLinkToCompare($object, $version)
	{
		$object->version = $version; //FIXME
		return link_to('<span title="Comparar con versión actual"></span>', $this->getUrlForAction('compare'), $object, array('class' => 'admin_td_action admin_td_action_default'));
	}

	public function imgLinkToDeleteVersion($object, $version)
	{
		return link_to('<span title="Eliminar"></span>', $this->getUrlForAction('deleteVersion'), $object, array('class' => 'admin_td_action admin_td_action_delete', 'onclick' => 'deleteVersion(this); return false;', 'version' => $version));
	}

	public function imgLinkToAction($object, $params, $action)
	{
		return link_to('<span title="' . $params['label'] . '"></span>', $this->getUrlForAction(trim($action)), $object, array('class' => 'admin_td_action admin_td_action_default'));
	}

	public function linkToNew($params)
	{
		return '<li class="admin_action_new">'.link_to('Nuevo', '@'.$this->getUrlForAction('new')).'</li>';
	}

	public function linkToEdit($object, $params)
	{
		return '<li class="admin_action_edit">'.link_to('Editar', $this->getUrlForAction('edit'), $object).'</li>';
	}

	public function linkToDelete($object, $params)
	{
		if ($object->isNew())
		{
			return '';
		}

		return '<li class="admin_action_delete">'.link_to('Borrar', $this->getUrlForAction('delete'), $object, array('method' => 'delete', 'confirm' => '¿Desea eliminar el elemento seleccionado?')).'</li>';
	}

	public function linkToShow($object, $text)
	{
		return '<li>'.link_to($text, $this->getUrlForAction('show'), $object).'</li>';
	}

	public function linkToHistoric($object)
	{
		return '<li class="admin_action_list">'.link_to('Historial de cambios', $this->getUrlForAction('historic'), $object ).'</li>';
	}

	public function linkToList($params)
	{
		return '<li class="admin_action_list">'.link_to('Listar', '@'.$this->getUrlForAction('list')).'</li>';
	}

	public function linkToSave($object, $params)
	{
		return '<li class="admin_action_save"><input type="submit" value="Guardar" /></li>';
	}

	public function linkToSaveAndAdd($object, $params)
	{
		if (!$object->isNew())
		{
			return '';
		}

		return '<li class="admin_action_save_and_add"><input type="submit" value="Guardar y crear otro" name="_save_and_add" /></li>';
	}

	public function linkToAction($param)
	{
		return sprintf('<li class="admin_action_%s">%s</li>', $param['class_suffix'], link_to($param['label'], '@' . $this->getUrlForAction($param['action']), array('target' => isset($param['target']) ? $param['target'] : '_self')));
	}

	public function linkToExtraAction($object, $param)
	{
		$field = isset($param['route_field']) ? $param['route_field'] : 'id';
		return '<li>' . link_to($param['label'], sprintf('@%s?%s=%s', $param['route'], $param['route_param'], $object->get($field))) . '</li>';
	}

	public function getArrayFieldValue(array $values) //compareSuccess
	{
		unset($values['id']);

		return implode(' ', $values);
	}

	public function getFieldValue($value, $config)
	{
		if (isset($config['renderer']))
			return call_user_func($config['renderer'], $value);

		return $value;
	}

	public function getFieldLabel($name, $config) //compareSuccess
	{
		if (isset($config) && isset($config['label']))
			return $config['label'];

		return sfInflector::humanize($name);
	}

}
